package leetcode.L500;

import java.util.TreeSet;

public class EX220 {
    public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {
        TreeSet<Long> set = new TreeSet<>();
        for (int i = 0, j = 0; i < nums.length; i++) {
            if(i-k>j){
                set.remove((long)nums[j]);
                j++;
            }
            Long temp = set.ceiling((long) nums[i] - (long) t);
            if(temp!=null&&temp<=(long) nums[i] + (long) t){
                return true;
            }
            set.add((long)nums[i]);
        }
        return false;
    }

    public static void main(String[] args) {
        int[] nums = {1,5,9,1,5,9};
        EX220 ex220 = new EX220();
        ex220.containsNearbyAlmostDuplicate(nums,2,3);


    }
}
